<?php

namespace app\middleware;

use ReflectionClass;
use Tinywan\Jwt\JwtToken;
use Tinywan\Jwt\Exception\JwtTokenException;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
use Tinywan\ExceptionHandler\Exception\BadRequestHttpException;
use support\Log;

class AuthUser implements MiddlewareInterface
{
    public function process(Request $request, callable $handler): Response
    {

        try {
            $request->uid = JwtToken::getCurrentId();
            return $handler($request);
        } catch (JwtTokenException $exception) {
            // 返回自己自定义的message格式
            return json(['code' => 4,'message' => $exception->getMessage()]);
        }
    }
}
